package server.config;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.List;
import java.util.Objects;


@Configuration
@PropertySource(value = "classpath:application.yml", ignoreResourceNotFound = true)
@SuppressWarnings("unused")
public class YamlConfig {

    @Value("#{'${spring.security.excludes}'.split(',')}")
    private List<String> excludesList; // 请求需要验证的路径

    @Value("#{'${spring.security.methods}'.split(',')}")
    private List<String> methods; // 请求需要验证请求方法

    private static String strList = null;// 预留内容

    public List<String> getMethods(){
        return this.methods;
    }
    @Value("${user.expire}")
    public long expire;
    /**
     * 获取字符串的参数
     *
     * @param joinChar 分割符号
     * @return str
     */
    public String getIncludesList(String joinChar) {
        if (StrUtil.isNotEmpty(strList)) {
            return strList;
        }
        if (Objects.isNull(excludesList) || excludesList.isEmpty()) {
            return strList;
        }
        StringBuffer stringBuffer = new StringBuffer();
        final int[] i = {0};
        int size = excludesList.size();
        excludesList.forEach(path -> {
            if (i[0] == size - 1) {
                stringBuffer.append(path);
            } else {
                stringBuffer.append(path).append(joinChar);
            }
            i[0] += 1;
        });
        strList = stringBuffer.toString();
        return strList;
    }

    public List<String> getExcludesList(){
        return excludesList;
    }

    public long getExpire() {
        return expire;
    }
}
